Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

executor: fix insert ignore invalid year #26097

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

Conversation

b41sh
Copy link
Member

@b41sh b41sh commented Jul 10, 2021

What problem does this PR solve?

Issue Number: close #25993

Problem Summary:

What is changed and how it works?

What's Changed: convert Invalid YEAR to 0000

Related changes

  • Need to cherry-pick to the release branch

Check List

Tests

  • Unit test

Release note

  • No release note

@ti-chi-bot ti-chi-bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Jul 10, 2021
@github-actions github-actions bot added the sig/execution SIG execution label Jul 10, 2021
table/column.go Outdated
@@ -265,6 +265,8 @@ func CastValue(ctx sessionctx.Context, val types.Datum, col *model.ColumnInfo, r
if innCasted, exit, innErr := handleZeroDatetime(ctx, col, casted, val.GetString(), types.ErrWrongValue.Equal(err)); exit {
return innCasted, innErr
}
} else if (sc.InInsertStmt || sc.InUpdateStmt) && err != nil && col.FieldType.Tp == mysql.TypeYear {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe usingtypes.ErrInvalidYear.Equal(err) instead of err != nil will be better.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have modified it, thanks. @mmyj

_, err = tk.Exec(`insert ignore into t values(1900);`)
c.Assert(err, IsNil)
tk.MustQuery("show warnings;").Check(testutil.RowsWithSep("|", "Warning|8033|invalid year"))
tk.MustQuery(`select * from t;`).Check(testkit.Rows(`0`))
Copy link
Member

@mmyj mmyj Jul 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the doc

YEAR follows the following format rules:

Four-digit numeral ranges from 1901 to 2155
Four-digit string ranges from '1901' to '2155'
One-digit or two-digit numeral ranges from 1 to 99. Accordingly, 1-69 is converted to 2001-2069 and 70-99 is converted to 1970-1999
One-digit or two-digit string ranges from '0' to '99'
Value 0 is taken as 0000 whereas the string '0' or '00' is taken as 2000
Invalid YEAR value is automatically converted to 0000 (if users are not using the NO_ZERO_DATE SQL mode).

I think we need to add a new test unit with the both valid and invalid case.

By the way, what value the invalid YEAR value will be converted when using NO_ZERO_DATE SQL mode? In my local, whatever using or not, the invalid value is always converted to 0.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I will add some test cases and check NO_ZERO_DATE mode

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mmyj
NO_ZERO_DATE will not affect the insertion of year type data, we can ignore it.
According to MySQL doc https://dev.mysql.com/doc/refman/8.0/en/sql-mode.html#sql-mode-strict
If the input parameter is an invalid value, an error will be produced only in strict SQL mode and without ignore, otherwise it can be inserted successfully and results in a warning.
I have add some test case, PTAL

@ti-chi-bot ti-chi-bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jul 15, 2021
@ti-chi-bot ti-chi-bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 16, 2021
_, err = tk.Exec(`insert ignore into t1 values(1900), (2156), ("1900"), ("2156");`)
c.Assert(err, IsNil)
tk.MustQuery("show warnings;").Check(testutil.RowsWithSep("|",
"Warning|8033|invalid year",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This warning is different with MySQL-8.0.23, MySQL-5.7.33, TiDB-5.7.25-TiDB-v4.0.11. They all will produce this error (1264, "Out of range value for column 'y' at row 1").

show warnings;
+---------+------+--------------------------------------------+
| Level   | Code | Message                                    |
+---------+------+--------------------------------------------+
| Warning | 1264 | Out of range value for column 'y' at row 1 |
| Warning | 1264 | Out of range value for column 'y' at row 2 |
| Warning | 1264 | Out of range value for column 'y' at row 3 |
| Warning | 1264 | Out of range value for column 'y' at row 4 |
+---------+------+--------------------------------------------+

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed this bug, but if I modified it, there will be some test cases that fail to pass, we'd better raise a new issue separately to deal with this problem.

Copy link
Member

@mmyj mmyj Jul 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Could you please help to create a bug issue and add a comment about it in this PR?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Copy link
Member

@mmyj mmyj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@ti-chi-bot
Copy link
Member

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • mmyj

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Jul 19, 2021
@ichn-hu ichn-hu mentioned this pull request Aug 11, 2021
@ti-chi-bot ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 22, 2021
@ti-chi-bot ti-chi-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 2, 2021
@ti-chi-bot ti-chi-bot bot deleted a comment from ti-chi-bot Dec 19, 2023
Copy link

tiprow bot commented Feb 27, 2024

@b41sh: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
tiprow_fast_test f7874d5 link true /test fast_test_tiprow

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

Copy link

ti-chi-bot bot commented Apr 10, 2024

@b41sh: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
idc-jenkins-ci-tidb/build f7874d5 link true /test build
idc-jenkins-ci-tidb/check_dev_2 f7874d5 link true /test check-dev2
idc-jenkins-ci-tidb/check_dev f7874d5 link true /test check-dev
idc-jenkins-ci-tidb/mysql-test f7874d5 link true /test mysql-test
pull-mysql-client-test f7874d5 link true /test pull-mysql-client-test
idc-jenkins-ci-tidb/unit-test f7874d5 link true /test unit-test
pull-integration-ddl-test f7874d5 link true /test pull-integration-ddl-test
pull-br-integration-test f7874d5 link true /test pull-br-integration-test
pull-lightning-integration-test f7874d5 link true /test pull-lightning-integration-test

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/execution SIG execution size/M Denotes a PR that changes 30-99 lines, ignoring generated files. status/LGT1 Indicates that a PR has LGTM 1.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

invalid year value cast incorrect
3 participants